home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume25 / trash / part06 < prev    next >
Encoding:
Text File  |  1992-03-23  |  36.0 KB  |  1,887 lines

  1. Newsgroups: comp.sources.unix
  2. From: bruce@beta.cs.su.oz.au (Bruce Janson)
  3. Subject: v25i160: trash - simulate process execution in MIPS RISC/os 4.52, Part06/08
  4. Sender: unix-sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: bruce@beta.cs.su.oz.au (Bruce Janson)
  8. Posting-Number: Volume 25, Issue 160
  9. Archive-Name: trash/part06
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 6 (of 8)."
  18. # Contents:  i_syscall.c
  19. # Wrapped by bruce@basser on Tue Mar  3 23:25:23 1992
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'i_syscall.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'i_syscall.c'\"
  23. else
  24. echo shar: Extracting \"'i_syscall.c'\" \(33351 characters\)
  25. sed "s/^X//" >'i_syscall.c' <<'END_OF_FILE'
  26. X#include    <sys/types.h>
  27. X#include    <sys/times.h>
  28. X#include    <sys/fs/prfcntl.h>
  29. X#include    <bsd/sys/types.h>
  30. X#include    <bsd/sys/socket.h>
  31. X#include    <bsd/sys/time.h>
  32. X#include    <bsd/netinet/in.h>
  33. X#include    <bsd/netdb.h>
  34. X#define    INKERNEL    1
  35. X#include    <signal.h>
  36. X#undef    INKERNEL
  37. X#include    <fcntl.h>
  38. X#include    <errno.h>
  39. X#include    <stdio.h>
  40. X#include    <unistd.h>
  41. X#include    "register.h"
  42. X#include    "symtab.h"
  43. X#include    "diblock.h"
  44. X#include    "instrn.h"
  45. X#include    "process.h"
  46. X#include    "sysentry.h"
  47. X#include    "res.h"
  48. X#include    "nels.h"
  49. X
  50. X#define            TRUNCATED_READ_WRITE_LENGTH    32
  51. X
  52. Xextern char        *malloc();
  53. Xextern char        *realloc();
  54. Xextern char        *ctime();
  55. Xextern char        *sysmess();
  56. Xextern sysentry        *sysv_systab_entry();
  57. Xextern sysentry        *bsd43_systab_entry();
  58. Xextern sysentry        *posix_systab_entry();
  59. X
  60. Xextern int        sysv_print_open_flags();
  61. Xextern int        bsd43_print_open_flags();
  62. Xextern int        posix_print_open_flags();
  63. X
  64. Xextern int        sysv_print_open_mode();
  65. Xextern int        bsd43_print_open_mode();
  66. Xextern int        posix_print_open_mode();
  67. X
  68. Xextern int        sysv_print_stat();
  69. Xextern int        bsd43_print_stat();
  70. Xextern int        posix_print_stat();
  71. X
  72. Xextern int        sysv_print_ioctl_cmd();
  73. Xextern int        bsd43_print_ioctl_cmd();
  74. Xextern int        posix_print_ioctl_cmd();
  75. X
  76. Xextern int        sysv_print_ioctl_arg();
  77. Xextern int        bsd43_print_ioctl_arg();
  78. Xextern int        posix_print_ioctl_arg();
  79. X
  80. Xextern int        sysv_print_fdset();
  81. Xextern int        bsd43_print_fdset();
  82. Xextern int        posix_print_fdset();
  83. X
  84. Xextern int        sysv_print_whence(); 
  85. Xextern int        bsd43_print_whence(); 
  86. Xextern int        posix_print_whence(); 
  87. X
  88. Xextern int        sysv_print_statfs(); 
  89. Xextern int        bsd43_print_statfs(); 
  90. Xextern int        posix_print_statfs(); 
  91. X
  92. Xextern int        sysv_print_sigcontext(); 
  93. Xextern int        bsd43_print_sigcontext(); 
  94. Xextern int        posix_print_sigcontext(); 
  95. X
  96. Xextern int        bsd43_print_sigvec(); 
  97. Xextern int        sysv_print_wait3_union_wait(); 
  98. Xextern int        sysv_print_wait3_options(); 
  99. Xextern int        sysv_print_wait3_rusage(); 
  100. X
  101. Xextern int        Aflag;
  102. Xextern int        Iflag;
  103. Xextern int        Nflag;
  104. Xextern int        Pflag;
  105. Xextern int        Sflag;
  106. Xextern int        Tflag;
  107. X
  108. Xextern char        *sys_errnolist[];
  109. Xextern int        sys_nerrno;
  110. Xextern FILE        *outfp;
  111. Xextern int        errno;
  112. Xextern unsigned long    instruction_count;
  113. Xextern unsigned long    instruction_count_since_last_syscall;
  114. X
  115. Xunsigned long        arg[NSYSARGS];    /* Arguments */
  116. X
  117. Xdinstrn            *GLOBALdipc;
  118. Xint            return_errno;    /* errno goes here. */
  119. Xlong            return_value0;    /* Result 1 value goes here. */
  120. Xlong            return_value1;    /* Result 2 value goes here. */
  121. X
  122. Xsysentry        *current_sysentp;
  123. Xchar            *sys_call_buf;    /* Scratch buf. */
  124. Xunsigned int        sys_call_bufz;    /* Current size of above. */
  125. X
  126. Xint            need_leading_pipe;
  127. X
  128. X/*
  129. X * Ensure that the scratch buffer (pointed to by 'sys_call_buf')
  130. X * is at least 'n' bytes long.
  131. X * Return -1 on error.
  132. X */
  133. Xint
  134. Xbufset(n)
  135. Xunsigned int    n;
  136. X{
  137. X    if (sys_call_bufz >= n)
  138. X        return 0;
  139. X
  140. X    if (sys_call_bufz == 0)
  141. X        sys_call_buf = malloc(n);
  142. X    else
  143. X        sys_call_buf = realloc(sys_call_buf, n);
  144. X
  145. X    if (sys_call_buf == (char *)0)
  146. X    {
  147. X        vcouldnot("expand syscall buffer to %d bytes", n);
  148. X        return -1;
  149. X    }
  150. X
  151. X    sys_call_bufz = n;
  152. X
  153. X    return 0;
  154. X}
  155. X
  156. X/*
  157. X * Return the length of the string that starts
  158. X * at address 'addr' in user memory (like strlen()).
  159. X * Return -1 on error.
  160. X */
  161. Xint
  162. Xmstrlen(addr)
  163. Xunsigned long    addr;
  164. X{
  165. X    int    length;
  166. X    char    c;
  167. X
  168. X    length = 0;
  169. X
  170. X    for (;;)
  171. X    {
  172. X        if (quiet_procmget(GLOBALdipc, addr, &c, sizeof(c)) == -1)
  173. X            return -1;
  174. X
  175. X        if (c == '\0')
  176. X            break;
  177. X
  178. X        length++;
  179. X        addr++;
  180. X    }
  181. X
  182. X    return length;
  183. X}
  184. X
  185. Xint
  186. Xmgetstring(p)
  187. Xlong    p;
  188. X{
  189. X    int    length;
  190. X
  191. X    if ((length = mstrlen(p)) == -1)
  192. X        return -1;
  193. X
  194. X    length++;
  195. X
  196. X    if (bufset((unsigned int)length) == -1)
  197. X        return -1;
  198. X
  199. X    if (quiet_procmget(GLOBALdipc, (unsigned long)p, sys_call_buf, length) == -1)
  200. X        return -1;
  201. X
  202. X    return length;
  203. X}
  204. X
  205. Xint
  206. Xmgets(addr, pp)
  207. Xunsigned long    addr;
  208. Xchar        **pp;
  209. X{
  210. X    int    length;
  211. X
  212. X    if (addr == (unsigned long)0)
  213. X    {
  214. X        *pp = (char *)0;
  215. X        return 0;
  216. X    }
  217. X
  218. X    if ((length = mstrlen(addr)) == -1)
  219. X        return -1;
  220. X
  221. X    length++;
  222. X
  223. X    if (bufset((unsigned int)length) == -1)
  224. X        return -1;
  225. X
  226. X    if (quiet_procmget(GLOBALdipc, addr, sys_call_buf, length) == -1)
  227. X        return -1;
  228. X
  229. X    *pp = sys_call_buf;
  230. X
  231. X    return length;
  232. X}
  233. X
  234. Xint
  235. Xmputstring(p)
  236. Xlong    p;
  237. X{
  238. X    int    length;
  239. X
  240. X    length = strlen(sys_call_buf);
  241. X
  242. X    length++;
  243. X
  244. X    if (quiet_procmput(GLOBALdipc, (unsigned long)p, sys_call_buf, length) == -1)
  245. X        return -1;
  246. X
  247. X    return length;
  248. X}
  249. X
  250. Xchar    **
  251. Xmgetvp(addr)
  252. Xunsigned long    addr;
  253. X{
  254. X    int        nargs;
  255. X    int        nchars;
  256. X    char        **result;
  257. X    unsigned long    saved_addr;
  258. X    char        **pp;
  259. X    char        *stringp;
  260. X
  261. X    saved_addr = addr;
  262. X    nargs = 0;
  263. X    nchars = 0;
  264. X
  265. X    for (;;)
  266. X    {
  267. X        char    *p;
  268. X        int    length;
  269. X
  270. X        if (quiet_procmget(GLOBALdipc, addr, &p, sizeof(p)) == -1)
  271. X            return (char **)0;
  272. X
  273. X        if (p == (char *)0)
  274. X            break;
  275. X
  276. X        if ((length = mstrlen(p)) == -1)
  277. X            return (char **)0;
  278. X
  279. X        nargs++;
  280. X        nchars += (length + 1);
  281. X        addr += sizeof(p);
  282. X    }
  283. X
  284. X    nargs++;
  285. X
  286. X    addr = saved_addr;
  287. X
  288. X    if ((result = (char **)malloc(sizeof(char *) * nargs + nchars)) == (char **)0)
  289. X    {
  290. X        vcouldnot("allocate %d bytes during execve arg processing", sizeof(char *) * nargs + nchars);
  291. X        return (char **)0;
  292. X    }
  293. X
  294. X    pp = result;
  295. X    stringp = (char *)(result + nargs);
  296. X
  297. X    for (;;)
  298. X    {
  299. X        char    *p;
  300. X        int    length;
  301. X
  302. X        if (quiet_procmget(GLOBALdipc, addr, &p, sizeof(p)) == -1)
  303. X            return (char **)0;
  304. X
  305. X        if (p == (char *)0)
  306. X            break;
  307. X
  308. X        if (mgetstring(p) == -1)
  309. X            return (char **)0;
  310. X
  311. X        *pp++ = stringp;
  312. X
  313. X        (void)strcpy(stringp, sys_call_buf);
  314. X        stringp += (strlen(sys_call_buf) + 1);
  315. X
  316. X        addr += sizeof(p);
  317. X    }
  318. X
  319. X    *pp = (char *)0;
  320. X
  321. X    return result;
  322. X}
  323. X
  324. Xint
  325. Xmfreevp(p)
  326. Xchar    **p;
  327. X{
  328. X    char    **cpp;
  329. X
  330. X    for (cpp = p; *cpp != (char *)0; cpp++)
  331. X        (void)free(*cpp);
  332. X
  333. X    (void)free((char *)cpp);
  334. X
  335. X    return 0;
  336. X}
  337. X
  338. Xint
  339. Xdmget(addr, n, pp)
  340. Xunsigned long    addr;
  341. Xint        n;
  342. Xchar        **pp;
  343. X{
  344. X    if (addr == (unsigned long)0)
  345. X        *pp = (char *)0;
  346. X    else
  347. X    {
  348. X        if (proc_mem_contiguous(addr, n, pp))
  349. X            return 0;
  350. X
  351. X        if (bufset(n) == -1)
  352. X            return -1;
  353. X
  354. X        if (quiet_procmget(GLOBALdipc, addr, sys_call_buf, n) == -1)
  355. X            return -1;
  356. X
  357. X        *pp = sys_call_buf;
  358. X    }
  359. X
  360. X    return 0;
  361. X}
  362. X
  363. Xint
  364. Xmget(addr, p, n, pp)
  365. Xunsigned long    addr;
  366. Xchar        *p;
  367. Xint        n;
  368. Xchar        **pp;
  369. X{
  370. X    if (addr == (unsigned long)0)
  371. X        *pp = (char *)0;
  372. X    else
  373. X    {
  374. X        if (quiet_procmget(GLOBALdipc, addr, p, n) == -1)
  375. X            return -1;
  376. X
  377. X        *pp = p;
  378. X    }
  379. X
  380. X    return 0;
  381. X}
  382. X
  383. Xint
  384. Xdmput(addr, p, n, s)
  385. Xunsigned long    addr;
  386. Xchar        *p;
  387. Xint        n;
  388. Xint        s;
  389. X{
  390. X    if (s != -1 && addr != (unsigned long)0 && p != (char *)0)
  391. X    {
  392. X        if (proc_mem_contiguous(addr, n, (char **)0))
  393. X            return 0;
  394. X
  395. X        if (quiet_procmput(GLOBALdipc, addr, p, n) == -1)
  396. X            return -1;
  397. X    }
  398. X
  399. X    return 0;
  400. X}
  401. X
  402. Xint
  403. Xmput(addr, p, n, s)
  404. Xunsigned long    addr;
  405. Xchar        *p;
  406. Xint        n;
  407. Xint        s;
  408. X{
  409. X    if (s != -1 && addr != (unsigned long)0 && p != (char *)0)
  410. X    {
  411. X        if (quiet_procmput(GLOBALdipc, addr, p, n) == -1)
  412. X            return -1;
  413. X    }
  414. X
  415. X    return 0;
  416. X}
  417. X
  418. Xstatic
  419. Xint
  420. Xget_syscall_arg(i, resultp)
  421. Xint        i;
  422. Xunsigned long    *resultp;
  423. X{
  424. X    unsigned long    sp;
  425. X
  426. X    switch (i)
  427. X    {
  428. X    case 0:
  429. X        if (quiet_procsget(R_V0, resultp) == -1)
  430. X            return -1;
  431. X        break;
  432. X
  433. X    case 1:
  434. X        if (quiet_procsget(R_A0, resultp) == -1)
  435. X            return -1;
  436. X        break;
  437. X
  438. X    case 2:
  439. X        if (quiet_procsget(R_A1, resultp) == -1)
  440. X            return -1;
  441. X        break;
  442. X
  443. X    case 3:
  444. X        if (quiet_procsget(R_A2, resultp) == -1)
  445. X            return -1;
  446. X        break;
  447. X
  448. X    case 4:
  449. X        if (quiet_procsget(R_A3, resultp) == -1)
  450. X            return -1;
  451. X        break;
  452. X
  453. X    default:
  454. X        if (quiet_procsget(R_SP, &sp) == -1)
  455. X            return -1;
  456. X
  457. X        if (quiet_procmget(GLOBALdipc, sp + (i - 1) * sizeof(int), resultp, sizeof(*resultp)) == -1)
  458. X            return -1;
  459. X        break;
  460. X    }
  461. X
  462. X    return 0;
  463. X}
  464. X
  465. Xstatic
  466. Xvoid
  467. Xvis_char(outfp, c)
  468. XFILE    *outfp;
  469. Xint    c;
  470. X{
  471. X    if (c >= ' ' && c <= '~') 
  472. X    {
  473. X        if (c == '\\' || c == '"')
  474. X            fprintf(outfp, "\\");
  475. X        fprintf(outfp, "%c", c);
  476. X    }
  477. X    else
  478. X    {
  479. X        switch (c)
  480. X        {
  481. X        case '\b':
  482. X            fprintf(outfp, "\\b");
  483. X            break;
  484. X
  485. X        case '\f':
  486. X            fprintf(outfp, "\\f");
  487. X            break;
  488. X
  489. X        case '\n':
  490. X            fprintf(outfp, "\\n");
  491. X            break;
  492. X
  493. X        case '\r':
  494. X            fprintf(outfp, "\\r");
  495. X            break;
  496. X
  497. X        case '\t':
  498. X            fprintf(outfp, "\\t");
  499. X            break;
  500. X
  501. X        default:
  502. X            fprintf(outfp, "\\%03o", c);
  503. X            break;
  504. X        }
  505. X    }
  506. X}
  507. X
  508. Xstatic
  509. Xvoid
  510. Xvis_string_with_quotes(outfp, p)
  511. XFILE    *outfp;
  512. Xchar    *p;
  513. X{
  514. X    if (p == (char *)0)
  515. X        fprintf(outfp, "(char *)0");
  516. X    else
  517. X    {
  518. X        fprintf(outfp, "\"");
  519. X        while (*p != '\0')
  520. X            vis_char(outfp, *p++);
  521. X        fprintf(outfp, "\"");
  522. X    }
  523. X}
  524. X
  525. Xvoid
  526. Xvis_quoted_truncated_buffer(outfp, truncated_length, buf, real_length)
  527. XFILE    *outfp;
  528. Xint    truncated_length;
  529. Xchar    *buf;
  530. Xlong    real_length;
  531. X{
  532. X    int    i;
  533. X
  534. X    if (buf == (char *)0)
  535. X        fprintf(outfp, "(char *)0");
  536. X    else
  537. X    {
  538. X        fprintf(outfp, "\"");
  539. X        for (i = 0; i < truncated_length; i++)
  540. X            vis_char(outfp, buf[i]);
  541. X        fprintf(outfp, "\"%s", (truncated_length < real_length) ? ".." : "");
  542. X    }
  543. X}
  544. X
  545. X/*
  546. X * See ~i/sys/signal.h
  547. X */
  548. Xstatic char    *signames[]    =
  549. X{
  550. X    "NULLSIG",        /* undefined */
  551. X    "SIGHUP",        /* hangup */
  552. X    "SIGINT",        /* interrupt (rubout) */
  553. X    "SIGQUIT",        /* quit (ASCII FS) */
  554. X    "SIGILL",        /* illegal instruction (not reset when caught)*/
  555. X    "SIGTRAP",        /* trace trap (not reset when caught) */
  556. X    "SIGABRT/SIGIOT",    /* IOT instruction used by abort */
  557. X    "SIGXCPU/SIGEMT",    /* exceeded CPU time limit/EMT instruction */
  558. X                /* SIGEMT (not possible on RISC/os) */
  559. X    "SIGFPE",        /* floating point exception */
  560. X    "SIGKILL",        /* kill (cannot be caught or ignored) */
  561. X    "SIGBUS",        /* bus error */
  562. X    "SIGSEGV",        /* segmentation violation */
  563. X    "SIGSYS",        /* bad argument to system call */
  564. X    "SIGPIPE",        /* write on a pipe with no one to read it */
  565. X    "SIGALRM",        /* alarm clock */
  566. X    "SIGTERM",        /* software termination signal from kill */
  567. X    "SIGUSR1",        /* user defined signal 1 */
  568. X    "SIGUSR2",        /* user defined signal 2 */
  569. X    "SIGCLD/SIGCHLD",    /* death of a child/4.3BSD's name */
  570. X    "SIGXFSZ/SIGPWR",    /* exceeded file size limit/power-fail */
  571. X                /* SIGPWR not possible on RISC/os */
  572. X    "SIGSTOP",        /* sendable stop signal not from tty */
  573. X    "SIGTSTP",        /* stop signal from tty */
  574. X    "SIGPOLL",        /* pollable event occured */
  575. X    "SIGIO",        /* input/output possible signal */
  576. X    "SIGURG",        /* urgent condition on IO channel */
  577. X    "SIGWINCH",        /* window size changes */
  578. X    "SIGVTALRM",        /* virtual time alarm */
  579. X    "SIGPROF",        /* profiling alarm */
  580. X    "SIGCONT",        /* continue a stopped process */
  581. X    "SIGTTIN",        /* to readers pgrp upon background tty read */
  582. X    "SIGTTOU",        /* like TTIN for output */
  583. X                /* -- if (tp->t_local<OSTOP) */
  584. X    "SIGLOST",        /* resource lost (eg, record-lock) */
  585. X};
  586. X
  587. Xchar    *
  588. Xsignal_name(s)
  589. Xunsigned long    s;
  590. X{
  591. X    static char    buf[128];
  592. X    int        signo;
  593. X    int        bits;
  594. X
  595. X    signo = s & SIGNO_MASK;
  596. X    bits = s & ~SIGNO_MASK;
  597. X
  598. X    if (signo >= 0 && signo < nels(signames))
  599. X        (void)strcpy(&buf[0], signames[signo]);
  600. X    else
  601. X        (void)sprintf(&buf[0], "%d", signo);
  602. X
  603. X    if ((bits & SIGDEFER) == SIGDEFER)
  604. X    {
  605. X        bits &= ~SIGDEFER;
  606. X        (void)strcat(&buf[0], "|SIGDEFER");
  607. X    }
  608. X
  609. X    if ((bits & SIGHOLD) == SIGHOLD)
  610. X    {
  611. X        bits &= ~SIGHOLD;
  612. X        (void)strcat(&buf[0], "|SIGHOLD");
  613. X    }
  614. X
  615. X    if ((bits & SIGRELSE) == SIGRELSE)
  616. X    {
  617. X        bits &= ~SIGRELSE;
  618. X        (void)strcat(&buf[0], "|SIGRELSE");
  619. X    }
  620. X
  621. X    if ((bits & SIGIGNORE) == SIGIGNORE)
  622. X    {
  623. X        bits &= ~SIGIGNORE;
  624. X        (void)strcat(&buf[0], "|SIGIGNORE");
  625. X    }
  626. X
  627. X    if ((bits & SIGPAUSE) == SIGPAUSE)
  628. X    {
  629. X        bits &= ~SIGPAUSE;
  630. X        (void)strcat(&buf[0], "|SIGPAUSE");
  631. X    }
  632. X
  633. X    if (bits != 0x0)
  634. X        (void)sprintf(&buf[0], "|0x%x", bits);
  635. X
  636. X    return &buf[0];
  637. X}
  638. X
  639. Xchar    *
  640. Xsignal_set(mask)
  641. Xunsigned long    mask;
  642. X{
  643. X    static char    buf[1024];
  644. X    int        s;
  645. X
  646. X    buf[0] = '\0';
  647. X
  648. X    (void)strcat(&buf[0], "{");
  649. X    for (s = 1; s < NSIG; s++)
  650. X    {
  651. X        unsigned long    m;
  652. X
  653. X        m = sigmask(s);
  654. X        if ((m & mask) == m)
  655. X        {
  656. X            (void)strcat(&buf[0], signames[s]);
  657. X            (void)strcat(&buf[0], ",");
  658. X            mask &= ~m;
  659. X        }
  660. X    }
  661. X    (void)strcat(&buf[0], "}");
  662. X
  663. X    if (mask != 0x0)
  664. X        (void)sprintf(&buf[strlen(&buf[0])], "0x%x", mask);
  665. X
  666. X    return &buf[0];
  667. X}
  668. X
  669. Xstatic char    *family[]    =
  670. X{
  671. X    "UNSPEC",
  672. X    "UNIX",
  673. X    "INET",
  674. X    "IMPLINK",
  675. X    "PUP",
  676. X    "CHAOS",
  677. X    "NS",
  678. X    "NBS",
  679. X    "ECMA",
  680. X    "DATAKIT",
  681. X    "CCITT",
  682. X    "SNA",
  683. X    "DECnet",
  684. X    "DLI",
  685. X    "LAT",
  686. X    "HYLINK",
  687. X    "APPLETALK",
  688. X};
  689. X
  690. Xstatic
  691. Xchar    *
  692. Xsay_family(f)
  693. Xint    f;
  694. X{
  695. X    static char    buf[16];
  696. X
  697. X    if (f < 0 || f >= nels(family))
  698. X        (void)sprintf(&buf[0], "%d", f);
  699. X    else
  700. X    {
  701. X        (void)strcpy(&buf[0], "AF_");
  702. X        (void)strcat(&buf[0], family[f]);
  703. X    }
  704. X
  705. X    return &buf[0];
  706. X}
  707. X
  708. Xstatic
  709. Xchar    *
  710. Xsay_addr(a)
  711. Xunsigned long    a;
  712. X{
  713. X    static char    buf[32];
  714. X    int        i;
  715. X
  716. X    buf[0] = '\0';
  717. X
  718. X    for (i = 0; i < sizeof(a); i++)
  719. X    {
  720. X        if (i != 0)
  721. X            buf[i * 4 - 1] = '.';
  722. X
  723. X        (void)sprintf(&buf[i * 4], "%03d", (a >> (24 - (i * 8))) & 0xFF);
  724. X    }
  725. X
  726. X    return &buf[0];
  727. X}
  728. X
  729. Xstatic
  730. Xvoid
  731. Xvis_address(outfp, s)
  732. XFILE        *outfp;
  733. Xstruct sockaddr    *s;
  734. X{
  735. X    if (s->sa_family == AF_INET)
  736. X    {
  737. X        struct sockaddr_in    is;
  738. X
  739. X        *(struct sockaddr_in *)&is = *(struct sockaddr_in *)s;
  740. X        fprintf(outfp, "{");
  741. X        fprintf(outfp, "port=%d,", is.sin_port);
  742. X        fprintf(outfp, "addr=%s", say_addr(is.sin_addr.s_addr));
  743. X        fprintf(outfp, "}");
  744. X    }
  745. X    else
  746. X        vis_quoted_truncated_buffer(outfp, sizeof(s->sa_data), &s->sa_data[0], sizeof(s->sa_data));
  747. X}
  748. X
  749. Xvoid
  750. Xsay_time(outfp, t)
  751. XFILE        *outfp;
  752. Xunsigned long    t;
  753. X{
  754. X    char    *cp;
  755. X
  756. X    cp = ctime(&t);
  757. X    cp[24] = '\0'; /* overwrite the newline */
  758. X    fprintf(outfp, "%lu[%s]", t, cp);
  759. X}
  760. X
  761. Xint
  762. Xprintval(universe, arg, desc, args, return_value0, return_value1, direction)
  763. Xint    universe;
  764. Xlong    arg;
  765. Xint    desc;
  766. Xlong    *args;
  767. Xlong    return_value0;
  768. Xlong    return_value1;
  769. Xint    direction;
  770. X{
  771. X    int        length;
  772. X    char        **app;
  773. X    char        **cpp;
  774. X    struct flock    sheep;
  775. X
  776. X    switch (desc)
  777. X    {
  778. X    case 'A':    /* ioctl arg */
  779. X        switch (universe)
  780. X        {
  781. X        case U_SYSV:
  782. X            return sysv_print_ioctl_arg(args); 
  783. X
  784. X        case U_BSD43:
  785. X            return bsd43_print_ioctl_arg(args); 
  786. X
  787. X        case U_POSIX:
  788. X            return posix_print_ioctl_arg(args); 
  789. X
  790. X        default:
  791. X            vcouldnot("print ioctl arg from unknown universe %d", universe);
  792. X            return -1;
  793. X        }
  794. X        break;
  795. X
  796. X    case 'B':    /* fcntl cmd */
  797. X        switch (arg)
  798. X        {
  799. X        case F_DUPFD:
  800. X            fprintf(outfp, "F_DUPFD");
  801. X            break;
  802. X
  803. X        case F_GETFD:
  804. X            fprintf(outfp, "F_GETFD");
  805. X            break;
  806. X
  807. X        case F_SETFD:
  808. X            fprintf(outfp, "F_SETFD");
  809. X            break;
  810. X
  811. X        case F_GETFL:
  812. X            fprintf(outfp, "F_GETFL");
  813. X            break;
  814. X
  815. X        case F_SETFL:
  816. X            fprintf(outfp, "F_SETFL");
  817. X            break;
  818. X
  819. X        case F_GETLK:
  820. X            fprintf(outfp, "F_GETLK");
  821. X            break;
  822. X
  823. X        case F_SETLK:
  824. X            fprintf(outfp, "F_SETLK");
  825. X            break;
  826. X
  827. X        case F_SETLKW:
  828. X            fprintf(outfp, "F_SETLKW");
  829. X            break;
  830. X
  831. X        case F_CHKFL:
  832. X            fprintf(outfp, "F_CHKFL");
  833. X            break;
  834. X
  835. X        case F_GETOWN:
  836. X            fprintf(outfp, "F_GETOWN");
  837. X            break;
  838. X
  839. X        case F_SETOWN:
  840. X            fprintf(outfp, "F_SETOWN");
  841. X            break;
  842. X
  843. X        case PFCSEXEC:
  844. X            fprintf(outfp, "PFCSEXEC");
  845. X            break;
  846. X
  847. X        case PFCREXEC:
  848. X            fprintf(outfp, "PFCREXEC");
  849. X            break;
  850. X
  851. X        case PFCRUN:
  852. X            fprintf(outfp, "PFCRUN");
  853. X            break;
  854. X
  855. X        case PFCSSTEP:
  856. X            fprintf(outfp, "PFCSSTEP");
  857. X            break;
  858. X
  859. X        case PFCCSIG:
  860. X            fprintf(outfp, "PFCCSIG");
  861. X            break;
  862. X
  863. X        case PFCWSTOP:
  864. X            fprintf(outfp, "PFCWSTOP");
  865. X            break;
  866. X
  867. X        case PFCGMASK:
  868. X            fprintf(outfp, "PFCGMASK");
  869. X            break;
  870. X
  871. X        case PFCSMASK:
  872. X            fprintf(outfp, "PFCSMASK");
  873. X            break;
  874. X
  875. X        case PFCSTOP:
  876. X            fprintf(outfp, "PFCSTOP");
  877. X            break;
  878. X
  879. X        case PFCGETPR:
  880. X            fprintf(outfp, "PFCGETPR");
  881. X            break;
  882. X
  883. X        case PFCGETUSEG:
  884. X            fprintf(outfp, "PFCGETUSEG");
  885. X            break;
  886. X
  887. X        case PFCGETREGS:
  888. X            fprintf(outfp, "PFCGETREGS");
  889. X            break;
  890. X
  891. X        default:
  892. X            fprintf(outfp, "0x%x", arg);
  893. X            break;
  894. X        }
  895. X        break;
  896. X
  897. X    case 'C':    /* ioctl cmd */
  898. X        switch (universe)
  899. X        {
  900. X        case U_SYSV:
  901. X            return sysv_print_ioctl_cmd(arg); 
  902. X
  903. X        case U_BSD43:
  904. X            return bsd43_print_ioctl_cmd(arg); 
  905. X
  906. X        case U_POSIX:
  907. X            return posix_print_ioctl_cmd(arg); 
  908. X
  909. X        default:
  910. X            vcouldnot("print ioctl cmd from unknown universe %d", universe);
  911. X            return -1;
  912. X        }
  913. X        break;
  914. X
  915. X    case 'D':    /* select fd_set */
  916. X        switch (universe)
  917. X        {
  918. X        case U_SYSV:
  919. X            return sysv_print_fdset(args[0], arg); 
  920. X
  921. X        case U_BSD43:
  922. X            return bsd43_print_fdset(args[0], arg); 
  923. X
  924. X        case U_POSIX:
  925. X            return posix_print_fdset(args[0], arg); 
  926. X
  927. X        default:
  928. X            vcouldnot("print fdset from unknown universe %d", universe);
  929. X            return -1;
  930. X        }
  931. X        break;
  932. X
  933. X    case 'E':    /* envp */
  934. X        fprintf(outfp, "{");
  935. X        if (Aflag)
  936. X        {
  937. X            if ((app = mgetvp(arg)) == (char **)0)
  938. X                return -1;
  939. X
  940. X            for (cpp = app; *cpp != (char *)0; cpp++)
  941. X            {
  942. X                vis_string_with_quotes(outfp, *cpp);
  943. X                fprintf(outfp, ",");
  944. X            }
  945. X
  946. X            if (mfreevp(app) == -1)
  947. X                return -1;
  948. X        }
  949. X        else
  950. X            fprintf(outfp, "..");
  951. X        fprintf(outfp, "}");
  952. X        break;
  953. X
  954. X    case 'F':    /* filename */
  955. X        {
  956. X            char    *cp;
  957. X
  958. X            if (mgets(arg, &cp) == -1)
  959. X                return -1;
  960. X
  961. X            vis_string_with_quotes(outfp, cp);
  962. X        }
  963. X        break;
  964. X
  965. X    case 'G':    /* getgroups() group set */
  966. X        fprintf(outfp, "{");
  967. X        if (direction == DIRN_EXIT)
  968. X        {
  969. X            length = return_value0;
  970. X
  971. X            if (length < 0)
  972. X                length = 0;
  973. X
  974. X            if (bufset((unsigned int)length * sizeof(int)) == -1)
  975. X                return -1;
  976. X
  977. X            if (quiet_procmget(GLOBALdipc, (unsigned long)arg, sys_call_buf, length * sizeof(int)) == -1)
  978. X                return -1;
  979. X
  980. X            {
  981. X                int    i;
  982. X
  983. X                for (i = 0; i < length; i++)
  984. X                    fprintf(outfp, "%d, ", ((int *)sys_call_buf)[i]);
  985. X            }
  986. X        }
  987. X        fprintf(outfp, "}");
  988. X        break;
  989. X
  990. X    case 'H':    /* fcntl arg */
  991. X        switch (args[1])
  992. X        {
  993. X        case F_DUPFD:
  994. X        case F_GETFD:
  995. X        case F_SETFD:
  996. X        case F_GETFL:
  997. X        case F_SETFL:
  998. X            fprintf(outfp, "0x%x", arg);
  999. X            break;
  1000. X
  1001. X        case F_GETLK:
  1002. X        case F_SETLK:
  1003. X        case F_SETLKW:
  1004. X            if (quiet_procmget(GLOBALdipc, arg, (char *)&sheep, sizeof(sheep)) == -1)
  1005. X                return -1;
  1006. X
  1007. X            fprintf(outfp, "{");
  1008. X            fprintf(outfp, "type=");
  1009. X            switch (sheep.l_type)
  1010. X            {
  1011. X            case F_RDLCK:
  1012. X                fprintf(outfp, "F_RDLCK");
  1013. X                break;
  1014. X
  1015. X            case F_WRLCK:
  1016. X                fprintf(outfp, "F_WRLCK");
  1017. X                break;
  1018. X
  1019. X            case F_UNLCK:
  1020. X                fprintf(outfp, "F_UNLCK");
  1021. X                break;
  1022. X
  1023. X            default:
  1024. X                fprintf(outfp, "0x%x", sheep.l_type);
  1025. X                break;
  1026. X            }
  1027. X            fprintf(outfp, ",");
  1028. X            fprintf(outfp, "whence=%d,", sheep.l_whence);
  1029. X            fprintf(outfp, "start=%d,", sheep.l_start);
  1030. X            fprintf(outfp, "len=%d,", sheep.l_len);
  1031. X            fprintf(outfp, "sysid=%d,", sheep.l_sysid);
  1032. X            fprintf(outfp, "pid=%d,", sheep.l_pid);
  1033. X            fprintf(outfp, "}");
  1034. X            break;
  1035. X
  1036. X        default:
  1037. X            fprintf(outfp, "0x%x", arg);
  1038. X            break;
  1039. X        }
  1040. X        break;
  1041. X
  1042. X
  1043. X    case 'I':    /* program address */
  1044. X        fprintf(outfp, "%s", proc_text_address(arg));
  1045. X        break;
  1046. X
  1047. X    case 'J':    /* signal action or program address */
  1048. X        switch (arg)
  1049. X        {
  1050. X        case SIG_ERR:
  1051. X            fprintf(outfp, "SIG_ERR");
  1052. X            break;
  1053. X
  1054. X        case SIG_DFL:
  1055. X            fprintf(outfp, "SIG_DFL");
  1056. X            break;
  1057. X
  1058. X        case SIG_IGN:
  1059. X            fprintf(outfp, "SIG_IGN");
  1060. X            break;
  1061. X
  1062. X        case SIG_HOLD:
  1063. X            fprintf(outfp, "SIG_HOLD");
  1064. X            break;
  1065. X
  1066. X        default:
  1067. X            fprintf(outfp, "%s", proc_text_address(arg));
  1068. X            break;
  1069. X        }
  1070. X        break;
  1071. X
  1072. X    case 'K':    /* signal name */
  1073. X        fprintf(outfp, "%s", signal_name(arg));
  1074. X        break;
  1075. X
  1076. X    case 'L':    /* struct sockaddr */
  1077. X        if (arg == (unsigned long)0)
  1078. X            fprintf(outfp, "0x%x", arg);
  1079. X        else
  1080. X        {
  1081. X            struct sockaddr    s;
  1082. X
  1083. X            if (quiet_procmget(GLOBALdipc, arg, (char *)&s, sizeof(s)) == -1)
  1084. X                return -1;
  1085. X
  1086. X            fprintf(outfp, "{");
  1087. X            fprintf(outfp, "family=%s,", say_family(s.sa_family));
  1088. X            fprintf(outfp, "sa_data=");
  1089. X            vis_address(outfp, &s);
  1090. X            fprintf(outfp, "}");
  1091. X        }
  1092. X        break;
  1093. X
  1094. X    case 'M':    /* signal set mask */
  1095. X        fprintf(outfp, "%s", signal_set(arg));
  1096. X        break;
  1097. X
  1098. X    case 'N':    /* send()/recv() flags */
  1099. X        if (arg == 0)
  1100. X            fprintf(outfp, "0x0");
  1101. X        else
  1102. X        {
  1103. X            int    need_bar;
  1104. X
  1105. X            need_bar = 0;
  1106. X            if (arg & MSG_OOB)
  1107. X            {
  1108. X                fprintf(outfp, "%s%s", need_bar ? "|" : "", "MSG_OOB");
  1109. X                need_bar = 1;
  1110. X                arg &= ~MSG_OOB;
  1111. X            }
  1112. X            if (arg & MSG_PEEK)
  1113. X            {
  1114. X                fprintf(outfp, "%s%s", need_bar ? "|" : "", "MSG_PEEK");
  1115. X                need_bar = 1;
  1116. X                arg &= ~MSG_PEEK;
  1117. X            }
  1118. X            if (arg & MSG_DONTROUTE)
  1119. X            {
  1120. X                fprintf(outfp, "%s%s", need_bar ? "|" : "", "MSG_DONTROUTE");
  1121. X                need_bar = 1;
  1122. X                arg &= ~MSG_DONTROUTE;
  1123. X            }
  1124. X            if (arg)
  1125. X                fprintf(outfp, "%s0x%x", need_bar ? "|" : "", arg);
  1126. X        }
  1127. X        break;
  1128. X
  1129. X    case 'O':    /* open flags */
  1130. X        switch (universe)
  1131. X        {
  1132. X        case U_SYSV:
  1133. X            return sysv_print_open_flags(arg); 
  1134. X
  1135. X        case U_BSD43:
  1136. X            return bsd43_print_open_flags(arg); 
  1137. X
  1138. X        case U_POSIX:
  1139. X            return posix_print_open_flags(arg); 
  1140. X
  1141. X        default:
  1142. X            vcouldnot("print open flags from unknown universe %d", universe);
  1143. X            return -1;
  1144. X        }
  1145. X        break;
  1146. X
  1147. X    case 'P':    /* access mode */
  1148. X        if (arg == 0)
  1149. X            fprintf(outfp, "F_OK");
  1150. X        else
  1151. X        {
  1152. X            int    need_bar;
  1153. X
  1154. X            need_bar = 0;
  1155. X            if (arg & R_OK)
  1156. X            {
  1157. X                fprintf(outfp, "%s%s", need_bar ? "|" : "", "R_OK");
  1158. X                need_bar = 1;
  1159. X                arg &= ~R_OK;
  1160. X            }
  1161. X            if (arg & W_OK)
  1162. X            {
  1163. X                fprintf(outfp, "%s%s", need_bar ? "|" : "", "W_OK");
  1164. X                need_bar = 1;
  1165. X                arg &= ~W_OK;
  1166. X            }
  1167. X            if (arg & X_OK)
  1168. X            {
  1169. X                fprintf(outfp, "%s%s", need_bar ? "|" : "", "X_OK");
  1170. X                need_bar = 1;
  1171. X                arg &= ~X_OK;
  1172. X            }
  1173. X            if (arg)
  1174. X                fprintf(outfp, "%s0x%x", need_bar ? "|" : "", arg);
  1175. X        }
  1176. X        break;
  1177. X
  1178. X    case 'Q':    /* pair of int's (as in utime()) */
  1179. X        if (arg == 0)
  1180. X            fprintf(outfp, "0x%x", arg);
  1181. X        else
  1182. X        {
  1183. X            int    i[2];
  1184. X
  1185. X            if (quiet_procmget(GLOBALdipc, (unsigned long)arg, &i[0], sizeof(i)) == -1)
  1186. X                return -1;
  1187. X
  1188. X            fprintf(outfp, "{");
  1189. X            say_time(outfp, i[0]);
  1190. X            fprintf(outfp, ",");
  1191. X            say_time(outfp, i[1]);
  1192. X            fprintf(outfp, "}");
  1193. X        }
  1194. X        break;
  1195. X
  1196. X    case 'R':    /* read() buffer */
  1197. X        if (direction == DIRN_ENTRY || args[0] == 100)
  1198. X            fprintf(outfp, "\"\"");
  1199. X        else
  1200. X        {
  1201. X            char    *cp;
  1202. X
  1203. X            length = return_value0;
  1204. X
  1205. X            if (length < 0)
  1206. X                length = 0;
  1207. X            else if (Aflag == 0 && length > TRUNCATED_READ_WRITE_LENGTH)
  1208. X                length = TRUNCATED_READ_WRITE_LENGTH;
  1209. X
  1210. X            if (dmget((unsigned long)arg, length, &cp) == -1)
  1211. X                return -1;
  1212. X
  1213. X            vis_quoted_truncated_buffer(outfp, length, cp, return_value0);
  1214. X        }
  1215. X        break;
  1216. X
  1217. X    case 'S':    /* struct stat */
  1218. X        if (direction == DIRN_EXIT)
  1219. X        {
  1220. X            switch (universe)
  1221. X            {
  1222. X            case U_SYSV:
  1223. X                return sysv_print_stat(arg); 
  1224. X
  1225. X            case U_BSD43:
  1226. X                return bsd43_print_stat(arg); 
  1227. X
  1228. X            case U_POSIX:
  1229. X                return posix_print_stat(arg); 
  1230. X
  1231. X            default:
  1232. X                vcouldnot("print stat structure from unknown universe %d", universe);
  1233. X                return -1;
  1234. X            }
  1235. X        }
  1236. X        break;
  1237. X
  1238. X    case 'T':    /* struct timeval */
  1239. X        if (arg == (unsigned long)0)
  1240. X            fprintf(outfp, "0x%x", arg);
  1241. X        else
  1242. X        {
  1243. X            struct timeval    t;
  1244. X
  1245. X            if (quiet_procmget(GLOBALdipc, arg, (char *)&t, sizeof(t)) == -1)
  1246. X                return -1;
  1247. X
  1248. X            fprintf(outfp, "{");
  1249. X            fprintf(outfp, "sec=%d,", t.tv_sec);
  1250. X            fprintf(outfp, "usec=%d", t.tv_usec);
  1251. X            fprintf(outfp, "}");
  1252. X        }
  1253. X        break;
  1254. X
  1255. X    case 'U':    /* pointer to an int */
  1256. X        if (arg == (unsigned long)0)
  1257. X            fprintf(outfp, "0x%x", arg);
  1258. X        else
  1259. X        {
  1260. X            int    i;
  1261. X
  1262. X            if (quiet_procmget(GLOBALdipc, arg, (char *)&i, sizeof(i)) == -1)
  1263. X                return -1;
  1264. X
  1265. X            fprintf(outfp, "{%d}", i);
  1266. X        }
  1267. X        break;
  1268. X
  1269. X    case 'V':    /* pair of struct timeval's */
  1270. X        if (arg == (unsigned long)0)
  1271. X            fprintf(outfp, "0x%x", arg);
  1272. X        else
  1273. X        {
  1274. X            struct timeval    t[2];
  1275. X
  1276. X            if (quiet_procmget(GLOBALdipc, arg, &t[0], sizeof(t)) == -1)
  1277. X                return -1;
  1278. X
  1279. X            fprintf(outfp, "{");
  1280. X            fprintf(outfp, "{");
  1281. X            fprintf(outfp, "sec=%d,", t[0].tv_sec);
  1282. X            fprintf(outfp, "usec=%d", t[0].tv_usec);
  1283. X            fprintf(outfp, "}");
  1284. X            fprintf(outfp, "{");
  1285. X            fprintf(outfp, "sec=%d,", t[1].tv_sec);
  1286. X            fprintf(outfp, "usec=%d", t[1].tv_usec);
  1287. X            fprintf(outfp, "}");
  1288. X            fprintf(outfp, "}");
  1289. X        }
  1290. X        break;
  1291. X
  1292. X    case 'W':    /* write() buffer */
  1293. X        {
  1294. X            char    *cp;
  1295. X
  1296. X            length = args[2];
  1297. X
  1298. X            if (Aflag == 0 && length > TRUNCATED_READ_WRITE_LENGTH)
  1299. X                length = TRUNCATED_READ_WRITE_LENGTH;
  1300. X
  1301. X            if (dmget((unsigned long)arg, length, &cp) == -1)
  1302. X                return -1;
  1303. X
  1304. X            vis_quoted_truncated_buffer(outfp, length, cp, args[2]);
  1305. X        }
  1306. X        break;
  1307. X
  1308. X    case 'X':    /* struct statfs */
  1309. X        switch (universe)
  1310. X        {
  1311. X        case U_SYSV:
  1312. X            return sysv_print_statfs(arg); 
  1313. X
  1314. X        case U_BSD43:
  1315. X            return bsd43_print_statfs(arg); 
  1316. X
  1317. X        case U_POSIX:
  1318. X            return posix_print_statfs(arg); 
  1319. X
  1320. X        default:
  1321. X            vcouldnot("print statfs structure from unknown universe %d", universe);
  1322. X            return -1;
  1323. X        }
  1324. X        break;
  1325. X
  1326. X    case 'Y':    /* result pair */
  1327. X        fprintf(outfp, "{%d,%d}", return_value0, return_value1);
  1328. X        break;
  1329. X
  1330. X    case 'Z':    /* struct timezone */
  1331. X        if (arg == (unsigned long)0)
  1332. X            fprintf(outfp, "0x%x", arg);
  1333. X        else
  1334. X        {
  1335. X            struct timezone    t;
  1336. X
  1337. X            if (quiet_procmget(GLOBALdipc, arg, (char *)&t, sizeof(t)) == -1)
  1338. X                return -1;
  1339. X
  1340. X            fprintf(outfp, "{");
  1341. X            fprintf(outfp, "minuteswest=%d,", t.tz_minuteswest);
  1342. X            fprintf(outfp, "dsttime=%d", t.tz_dsttime);
  1343. X            fprintf(outfp, "}");
  1344. X        }
  1345. X        break;
  1346. X
  1347. X    case 'a':    /* socket domain */
  1348. X        switch (arg)
  1349. X        {
  1350. X        case PF_UNIX:
  1351. X            fprintf(outfp, "PF_UNIX");
  1352. X            break;
  1353. X
  1354. X        case PF_INET:
  1355. X            fprintf(outfp, "PF_INET");
  1356. X            break;
  1357. X
  1358. X        case PF_NS:
  1359. X            fprintf(outfp, "PF_NS");
  1360. X            break;
  1361. X
  1362. X        case PF_IMPLINK:
  1363. X            fprintf(outfp, "PF_IMPLINK");
  1364. X            break;
  1365. X
  1366. X        default:
  1367. X            fprintf(outfp, "%d", arg);
  1368. X            break;
  1369. X        }
  1370. X        break;
  1371. X
  1372. X    case 'b':    /* socket type */
  1373. X        switch (arg)
  1374. X        {
  1375. X        case SOCK_STREAM:
  1376. X            fprintf(outfp, "SOCK_STREAM");
  1377. X            break;
  1378. X
  1379. X        case SOCK_DGRAM:
  1380. X            fprintf(outfp, "SOCK_DGRAM");
  1381. X            break;
  1382. X
  1383. X        case SOCK_RAW:
  1384. X            fprintf(outfp, "SOCK_RAW");
  1385. X            break;
  1386. X
  1387. X        case SOCK_SEQPACKET:
  1388. X            fprintf(outfp, "SOCK_SEQPACKET");
  1389. X            break;
  1390. X
  1391. X        case SOCK_RDM:
  1392. X            fprintf(outfp, "SOCK_RDM");
  1393. X            break;
  1394. X
  1395. X        default:
  1396. X            fprintf(outfp, "%d", arg);
  1397. X            break;
  1398. X        }
  1399. X        break;
  1400. X
  1401. X    case 'c':    /* socket protocol */
  1402. X        {
  1403. X            struct protoent    *p;
  1404. X
  1405. X            if
  1406. X            (
  1407. X                args[0] == PF_INET
  1408. X                &&
  1409. X                (p = getprotobynumber(arg)) != (struct protoent *)0
  1410. X            )
  1411. X                fprintf(outfp, "%s", p->p_name);
  1412. X            else
  1413. X                fprintf(outfp, "%d", arg);
  1414. X        }
  1415. X        break;
  1416. X
  1417. X    case 'd':    /* int */
  1418. X        fprintf(outfp, "%d", arg);
  1419. X        break;
  1420. X
  1421. X    case 'e':    /* int -- result from execve()/exit() see i_syscall() */
  1422. X        fprintf(outfp, "%d", arg);
  1423. X        break;
  1424. X
  1425. X    case 'f':    /* pointer to a struct sigvec */
  1426. X        if (bsd43_print_sigvec(arg) == -1)
  1427. X            return -1;
  1428. X        break;
  1429. X
  1430. X    case 'g':    /* setgroups() group set */
  1431. X        fprintf(outfp, "{");
  1432. X        {
  1433. X            length = args[0];
  1434. X
  1435. X            if (length < 0)
  1436. X                length = 0;
  1437. X
  1438. X            if (bufset((unsigned int)length * sizeof(int)) == -1)
  1439. X                return -1;
  1440. X
  1441. X            if (quiet_procmget(GLOBALdipc, (unsigned long)arg, sys_call_buf, length * sizeof(int)) == -1)
  1442. X                return -1;
  1443. X
  1444. X            {
  1445. X                int    i;
  1446. X
  1447. X                for (i = 0; i < length; i++)
  1448. X                    fprintf(outfp, "%d, ", ((int *)sys_call_buf)[i]);
  1449. X            }
  1450. X        }
  1451. X        fprintf(outfp, "}");
  1452. X        break;
  1453. X
  1454. X    case 'h':    /* wait3 union wait */
  1455. X        if (sysv_print_wait3_union_wait(arg) == -1)
  1456. X            return -1;
  1457. X        break;
  1458. X
  1459. X    case 'i':    /* wait3 options */
  1460. X        if (sysv_print_wait3_options(arg) == -1)
  1461. X            return -1;
  1462. X        break;
  1463. X
  1464. X    case 'j':    /* wait3 rusage */
  1465. X        if (sysv_print_wait3_rusage(arg) == -1)
  1466. X            return -1;
  1467. X        break;
  1468. X
  1469. X    case 'k':    /* times tms */
  1470. X        {
  1471. X            struct tms    t;
  1472. X            struct tms    *tp;
  1473. X
  1474. X            if (mget(arg, &t, sizeof(t), &tp) == -1)
  1475. X                return -1;
  1476. X
  1477. X            if (tp == (struct tms *)0)
  1478. X                fprintf(outfp, "0x%x", arg);
  1479. X            else
  1480. X            {
  1481. X                fprintf(outfp, "{" /* } */);
  1482. X
  1483. X                fprintf(outfp, "utime=%d,", t.tms_utime);
  1484. X                fprintf(outfp, "stime=%d,", t.tms_stime);
  1485. X                fprintf(outfp, "cutime=%d,", t.tms_cutime);
  1486. X                fprintf(outfp, "cstime=%d,", t.tms_cstime);
  1487. X
  1488. X                fprintf(outfp, /* { */ "}");
  1489. X            }
  1490. X
  1491. X            return 0;
  1492. X        }
  1493. X        break;
  1494. X
  1495. X    case 'l':    /* argp */
  1496. X        fprintf(outfp, "{");
  1497. X        if (Aflag)
  1498. X        {
  1499. X            if ((app = mgetvp(arg)) == (char **)0)
  1500. X                return -1;
  1501. X
  1502. X            for (cpp = app; *cpp != (char *)0; cpp++)
  1503. X            {
  1504. X                vis_string_with_quotes(outfp, *cpp);
  1505. X                fprintf(outfp, ",");
  1506. X            }
  1507. X
  1508. X            if (mfreevp(app) == -1)
  1509. X                return -1;
  1510. X        }
  1511. X        else
  1512. X            fprintf(outfp, "..");
  1513. X        fprintf(outfp, "}");
  1514. X        break;
  1515. X
  1516. X    case 'm':    /* file creation mode */
  1517. X        fprintf(outfp, "%s%o", (arg == 0) ? "" : "0", arg);
  1518. X        break;
  1519. X
  1520. X    case 'o':    /* octal int */
  1521. X        fprintf(outfp, "%s%o", (arg == 0) ? "" : "0", arg);
  1522. X        break;
  1523. X
  1524. X    case 'p':    /* pointer */
  1525. X    case 'x':    /* " */
  1526. X        fprintf(outfp, "0x%x", arg);
  1527. X        break;
  1528. X
  1529. X    case 's':    /* outgoing string */
  1530. X        if (direction == DIRN_EXIT)
  1531. X        {
  1532. X            char    *cp;
  1533. X
  1534. X            if (mgets(arg, &cp) == -1)
  1535. X                return -1;
  1536. X
  1537. X            vis_string_with_quotes(outfp, cp);
  1538. X        }
  1539. X        break;
  1540. X
  1541. X    case 't':    /* time_t */
  1542. X        say_time(outfp, arg);
  1543. X        break;
  1544. X
  1545. X    case 'u':    /* unsigned long */
  1546. X        fprintf(outfp, "%lu", arg);
  1547. X        break;
  1548. X
  1549. X    case 'v':    /* pointer to a time_t */
  1550. X        if (arg == (unsigned long)0)
  1551. X            fprintf(outfp, "0x%x", arg);
  1552. X        else
  1553. X        {
  1554. X            long    i;
  1555. X
  1556. X            if (quiet_procmget(GLOBALdipc, arg, (char *)&i, sizeof(i)) == -1)
  1557. X                return -1;
  1558. X
  1559. X            fprintf(outfp, "{");
  1560. X            say_time(outfp, i);
  1561. X            fprintf(outfp, "}");
  1562. X        }
  1563. X        break;
  1564. X
  1565. X    case 'w':    /* lseek() whence */
  1566. X        switch (universe)
  1567. X        {
  1568. X        case U_SYSV:
  1569. X            return sysv_print_whence(arg); 
  1570. X
  1571. X        case U_BSD43:
  1572. X            return bsd43_print_whence(arg); 
  1573. X
  1574. X        case U_POSIX:
  1575. X            return posix_print_whence(arg); 
  1576. X
  1577. X        default:
  1578. X            vcouldnot("print whence from unknown universe %d", universe);
  1579. X            return -1;
  1580. X        }
  1581. X        break;
  1582. X
  1583. X    case 'y':    /* sigcontext */
  1584. X        switch (universe)
  1585. X        {
  1586. X        case U_SYSV:
  1587. X            return sysv_print_sigcontext(outfp, arg);
  1588. X
  1589. X        case U_BSD43:
  1590. X            return bsd43_print_sigcontext(outfp, arg);
  1591. X
  1592. X        case U_POSIX:
  1593. X            return posix_print_sigcontext(outfp, arg);
  1594. X
  1595. X        default:
  1596. X            vcouldnot("print sigcontext from unknown universe %d", universe);
  1597. X            return -1;
  1598. X        }
  1599. X        break;
  1600. X
  1601. X    case '\0':    /* unknown */
  1602. X    default:    /* " */
  1603. X        fprintf(outfp, "0x%x", arg);
  1604. X        break;
  1605. X    }
  1606. X
  1607. X    return 0;
  1608. X}
  1609. X
  1610. Xstatic
  1611. Xchar    *
  1612. Xsay_errno(e)
  1613. Xint    e;
  1614. X{
  1615. X    if (e < 0 || e >= sys_nerrno)
  1616. X        e = 0;
  1617. X
  1618. X    return sys_errnolist[e];
  1619. X}
  1620. X
  1621. Xstatic
  1622. Xint
  1623. Xshow_syscall(universe, universe_name, current_sysentp, argp, return_value0, return_value1, return_errno, direction)
  1624. Xint        universe;
  1625. Xchar        *universe_name;
  1626. Xsysentry    *current_sysentp;
  1627. Xunsigned long    *argp;
  1628. Xlong        return_value0;
  1629. Xlong        return_value1;
  1630. Xint        return_errno;
  1631. Xint        direction;
  1632. X{
  1633. X    int    i;
  1634. X
  1635. X    fprintf(outfp, "%6d:", P.p_pid);
  1636. X
  1637. X    fprintf(outfp, "%s_", universe_name);
  1638. X
  1639. X    fprintf(outfp, "%s(", (current_sysentp->sy_name == (char *)0) ? "<unknown>" : current_sysentp->sy_name);
  1640. X
  1641. X    for (i = 0; i < current_sysentp->sy_narg; i++)
  1642. X    {
  1643. X        if (i != 0)
  1644. X            fprintf(outfp, ", ");
  1645. X        if (printval(universe, argp[i], (int)current_sysentp->sy_desc[i], argp, return_value0, return_value1, direction) == -1)
  1646. X            return -1;
  1647. X    }
  1648. X
  1649. X    fprintf(outfp, ")");
  1650. X
  1651. X    if (direction == DIRN_EXIT)
  1652. X    {
  1653. X        fprintf(outfp, " = ");
  1654. X
  1655. X        if (printval(universe, return_value0, (int)current_sysentp->sy_rdesc, argp, return_value0, return_value1, direction) == -1)
  1656. X            return -1;
  1657. X
  1658. X        if (return_errno != 0)
  1659. X        {
  1660. X            int    saved_errno;
  1661. X
  1662. X            saved_errno = errno;
  1663. X            errno = return_errno;
  1664. X            fprintf(outfp, " %s (%s)", say_errno(return_errno), sysmess());
  1665. X            errno = saved_errno;
  1666. X        }
  1667. X    }
  1668. X
  1669. X    if (Nflag)
  1670. X    {
  1671. X        fprintf(outfp, " [%d,%d]", instruction_count_since_last_syscall, instruction_count);
  1672. X        instruction_count_since_last_syscall = 0;
  1673. X    }
  1674. X
  1675. X    if (Tflag)
  1676. X        res_print();
  1677. X
  1678. X    fprintf(outfp, "\n");
  1679. X
  1680. X    return 0;
  1681. X}
  1682. X
  1683. Xdinstrn    *
  1684. Xi_syscall(dipc, rs, rt, rd, shamt, funct)
  1685. Xdinstrn    *dipc;
  1686. Xint    rs;
  1687. Xint    rt;
  1688. Xint    rd;
  1689. Xint    shamt;
  1690. Xint    funct;
  1691. X{
  1692. X    int        stacki;
  1693. X    unsigned long    real_syscall_number;
  1694. X    int        syscall_number;
  1695. X    int        universe;
  1696. X    char        *universe_name;
  1697. X    int        argi;
  1698. X    int        r;
  1699. X    int        (*fp)();
  1700. X
  1701. X    errno = 0;
  1702. X
  1703. X    stacki = 0;
  1704. X
  1705. X    current_sysentp = (sysentry *)0;
  1706. X    universe_name = "<unknown universe>";
  1707. X
  1708. X    GLOBALdipc = dipc;
  1709. X
  1710. X    /*
  1711. X     * Determine the system call number,
  1712. X     * doing any indirection as required.
  1713. X     */
  1714. X    for (;;)
  1715. X    {
  1716. X        if (get_syscall_arg(stacki++, &real_syscall_number) == -1)
  1717. X            return dipc;
  1718. X
  1719. X        syscall_number = real_syscall_number % 1000;
  1720. X
  1721. X        /*
  1722. X         * This next test should really refer to
  1723. X         *    SYS_syscall
  1724. X         *    BSD43_SYS_syscall
  1725. X         *    POSIX_SYS_syscall
  1726. X         * but the latter exists instead as
  1727. X         *    SYS_syscall
  1728. X         * which would cause an embarrassing
  1729. X         * name clash.
  1730. X         * They all expand to 0 anyway,
  1731. X         * so that's what we use.
  1732. X         */
  1733. X        if (syscall_number == 0)
  1734. X            continue;
  1735. X
  1736. X        switch (universe = real_syscall_number / 1000)
  1737. X        {
  1738. X        case U_SYSV:
  1739. X            universe_name = "sysv";
  1740. X            current_sysentp = sysv_systab_entry(syscall_number);
  1741. X            break;
  1742. X
  1743. X        case U_BSD43:
  1744. X            universe_name = "bsd43";
  1745. X            current_sysentp = bsd43_systab_entry(syscall_number);
  1746. X            break;
  1747. X
  1748. X        case U_POSIX:
  1749. X            universe_name = "posix";
  1750. X            current_sysentp = posix_systab_entry(syscall_number);
  1751. X            break;
  1752. X
  1753. X        case 0:
  1754. X        default:
  1755. X            break;
  1756. X        }
  1757. X
  1758. X        break;
  1759. X    }
  1760. X
  1761. X    if (current_sysentp == (sysentry *)0)
  1762. X    {
  1763. X        vcouldnot("execute unimplemented %s system call #%d", universe_name, real_syscall_number);
  1764. X        return dipc;
  1765. X    }
  1766. X
  1767. X    if ((fp = current_sysentp->sy_call) == (int (*)())0)
  1768. X    {
  1769. X        vcouldnot("execute unimplemented %s system call \"%s\" [#%d]", universe_name, (current_sysentp->sy_name == (char *)0) ? "" : current_sysentp->sy_name, real_syscall_number);
  1770. X        return dipc;
  1771. X    }
  1772. X
  1773. X    /*
  1774. X     * Get the system call's arguments.
  1775. X     */
  1776. X    for (argi = 0; argi < current_sysentp->sy_narg; argi++)
  1777. X    {
  1778. X        if (get_syscall_arg(stacki++, &arg[argi]) == -1)
  1779. X            return dipc;
  1780. X    }
  1781. X
  1782. X    /*
  1783. X     * Print system call arguments before execution if desired.
  1784. X     * (The 'e' kludge is for execve() and exit()...)
  1785. X     */
  1786. X    if (Pflag || (Sflag && current_sysentp->sy_rdesc == 'e'))
  1787. X    {
  1788. X        if (show_syscall(universe, universe_name, current_sysentp, &arg[0], (long)0, (long)0, 0, DIRN_ENTRY) == -1)
  1789. X            return dipc;
  1790. X    }
  1791. X
  1792. X    /*
  1793. X     * Run the system call.
  1794. X     */
  1795. X    switch (r = (*fp)(real_syscall_number))
  1796. X    {
  1797. X    case 0:        /* OK */
  1798. X        dipc = GLOBALdipc;
  1799. X        break;
  1800. X
  1801. X    case -1:    /* Some internal error. */
  1802. X        dipc = GLOBALdipc;
  1803. X        return dipc;
  1804. X
  1805. X    case -2:    /* Unimpl. feature. */
  1806. X        dipc = GLOBALdipc;
  1807. X        if (!Pflag && !(Sflag && current_sysentp->sy_rdesc == 'e'))
  1808. X        {
  1809. X            if (show_syscall(universe, universe_name, current_sysentp, &arg[0], (long)0, (long)0, 0, DIRN_ENTRY) == -1)
  1810. X                return dipc;
  1811. X        }
  1812. X
  1813. X        vcouldnot("execute unimplemented feature of %s system call \"%s\" [#%d]", universe_name, (current_sysentp->sy_name == (char *)0) ? "" : current_sysentp->sy_name, real_syscall_number);
  1814. X        return dipc;
  1815. X
  1816. X    case -3:    /* OK, but don't copy errno/values to registers. */
  1817. X        dipc = GLOBALdipc;
  1818. X        break;
  1819. X
  1820. X    default:    /* Somebody stuffed up ... */
  1821. X        dipc = GLOBALdipc;
  1822. X        vcouldnot("execute %s system call \"%s\" [#%d]: unrecognised return value: %d", universe_name, (current_sysentp->sy_name == (char *)0) ? "" : current_sysentp->sy_name, real_syscall_number, r);
  1823. X        return dipc;
  1824. X    }
  1825. X
  1826. X    if (r != -3)
  1827. X    {
  1828. X        /*
  1829. X         * Pass back errno and return values.
  1830. X         */
  1831. X        if (return_errno == 0)
  1832. X        {
  1833. X            if (quiet_procsput(R_V0, (unsigned long)return_value0) == -1)
  1834. X                return dipc;
  1835. X
  1836. X            if (quiet_procsput(R_V1, (unsigned long)return_value1) == -1)
  1837. X                return dipc;
  1838. X
  1839. X            if (quiet_procsput(R_A3, 0) == -1)
  1840. X                return dipc;
  1841. X        }
  1842. X        else
  1843. X        {
  1844. X            if (quiet_procsput(R_V0, (unsigned long)return_errno) == -1)
  1845. X                return dipc;
  1846. X
  1847. X            if (quiet_procsput(R_A3, 1) == -1)
  1848. X                return dipc;
  1849. X        }
  1850. X    }
  1851. X
  1852. X    /*
  1853. X     * Print system call arguments and results
  1854. X     * after execution if desired.
  1855. X     */
  1856. X    if (Sflag)
  1857. X    {
  1858. X        if (show_syscall(universe, universe_name, current_sysentp, &arg[0], return_value0, return_value1, return_errno, DIRN_EXIT) == -1)
  1859. X            return dipc;
  1860. X    }
  1861. X
  1862. X    return dipc;
  1863. X}
  1864. END_OF_FILE
  1865. if test 33351 -ne `wc -c <'i_syscall.c'`; then
  1866.     echo shar: \"'i_syscall.c'\" unpacked with wrong size!
  1867. fi
  1868. # end of 'i_syscall.c'
  1869. fi
  1870. echo shar: End of archive 6 \(of 8\).
  1871. cp /dev/null ark6isdone
  1872. MISSING=""
  1873. for I in 1 2 3 4 5 6 7 8 ; do
  1874.     if test ! -f ark${I}isdone ; then
  1875.     MISSING="${MISSING} ${I}"
  1876.     fi
  1877. done
  1878. if test "${MISSING}" = "" ; then
  1879.     echo You have unpacked all 8 archives.
  1880.     rm -f ark[1-9]isdone
  1881. else
  1882.     echo You still need to unpack the following archives:
  1883.     echo "        " ${MISSING}
  1884. fi
  1885. ##  End of shell archive.
  1886. exit 0
  1887.